class Solution {
public:
    vector<vector<string> > ret;
    vector<string> path;
    void dfs(vector<vector<int> >& dp,string& s,int cur){
        if(cur >= s.size()){
            ret.push_back(path);
            return;
        }
        for(int i = cur;i < s.size();i++){
            if(dp[cur][i]){
                path.push_back(s.substr(cur,i-cur+1));
                dfs(dp,s,i+1);
                path.pop_back();
            }
        }
    }
    vector<vector<string>> partition(string s) {
        vector<vector<int> > dp(s.size(),vector<int>(s.size(),0));
        for(int i = s.size() - 1;i >= 0;i--){
            for(int j = i;j < s.size();j++){
                if(s[i] == s[j]){
                    if(j - i <= 2){
                        dp[i][j] = 1;
                    }else{
                        dp[i][j] = dp[i + 1][j - 1];
                    }
                }
            }
        }
   
